/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package researchgrants.parts.GrantRequest.nsfcode;

import java.util.List;
import java.util.Iterator;
import researchgrants.parts.LoggedData.panels.trees.LoggedDataPanelsTree;
import researchgrants.parts.LoggedData.panels.trees.TreeNode;
import researchgrants.parts.LoggedData.panels.trees.TreeableLoggedData;

/**
 * This class allows a panels to choose an nsf-code from an nsf-codes' tree
 * @author DOStudent1
 */
public class LoggedDataPanelsTreeNsfCode extends LoggedDataPanelsTree {

        
    public TreeNode<TreeableLoggedData> getTree() {
        return(getTree(NsfCode.getTopMostNsfCode()));
    }
    
    // recursively load the tree
    private TreeNode<TreeableLoggedData> getTree(NsfCode currentLevel) {
        TreeNode<TreeableLoggedData> tree=new TreeNode<TreeableLoggedData>(currentLevel);
        List<TreeableLoggedData> sonsNsfCodes = currentLevel.getSons();
        for (Iterator<TreeableLoggedData> it = sonsNsfCodes.iterator(); it.hasNext();) {
            NsfCode nsfCode = (NsfCode)it.next();
            tree.addSon(getTree(nsfCode));
        }
        return(tree);
    }
}
